#ifndef CONNECTTHREAD_H
#define CONNECTTHREAD_H


#include <memory>
#include <thread>
#include <mutex>
#include <queue>
#include <condition_variable>

using namespace std;

class SocketContext;

class ConnectThread
{
public:
    ConnectThread() = default;

    void init();
    void wait();
    void quit();
    void uninit();
    void push(const shared_ptr<SocketContext> &sock);
    static shared_ptr<ConnectThread> &instance();

protected:
   void run();
   void handproc();
   pair<shared_ptr<SocketContext>, bool> pop();

private:
    static queue<shared_ptr<SocketContext>> que;
    thread      connectthread;
    mutex       lmtx;

    condition_variable cv;
    mutex  mtx;
    bool   bnotify{false}, bquit{false};
};

#define _C_T_      ConnectThread::instance()

#endif // CONNECTTHREAD_H
